<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
          <script type="text/javascript" src="../js/jquery-1.9.1.js"></script>
     </head>   
<body>

 
<script type="text/javascript">
 //测试controller是否可以进入
ajaxDo("/activemq-client/index",null);

function ajaxDo(url,data){
	 $.ajax({
	        url:url ,
	        type: "post",
	        dataType: "json",
	        data: data,
	        success:function(result){
	           if(result.success){
	        	   alert(result.data);
	           }else{
	        	   alert(result.msg);
	           }
	        }
	    });
}


//--------------------------------- webSocket ----------------------------------------------
  initSocket("user");
  initSocket("news");
  initSocket("client");
  

function initSocket(myWebsocket) {
	
	var webSocket = null;
	
    window.onbeforeunload = function () {
        //离开页面时的其他操作
    };

    if (!window.WebSocket) {
        console("您的浏览器不支持websocket！");
        return false;
    }

    var target = 'ws://' + window.location.host + "/activemq-client/websocket/"+myWebsocket;
		  
		if ('WebSocket' in window) {  
			webSocket = new WebSocket(target);  
		} else if ('MozWebSocket' in window) {  
			webSocket = new MozWebSocket(target);  
		} else {  
		    alert('WebSocket is not supported by this browser.');  
		    return;  
		}  
    
    
    // 收到服务端消息
    webSocket.onmessage = function (msg) {
            alert(msg.data);
        // 关闭连接
        webSocket.onclose();
        console.log(msg);
    };

    // 异常
    webSocket.onerror = function (event) {
        console.log(event);
    };

    // 建立连接
    webSocket.onopen = function (event) {
        console.log(event);
    };

    // 断线
    webSocket.onclose = function () {
		
        console.log("websocket断开连接");
    };
}


</script>

</body>
</html>